//
// Copyright (C) 2011 Steve Channell steve.channell@cepheis.com
//
// This file is part of Cephei.QL, an open-source library wrapper 
// arround QuantLib http://quantlib.org/
//
// Cephei.QL is open source software: you can redistribute it and/or modify it
// under the terms of the license.  You should have received a
// copy of the license along with this program; if not, please email
// <support@cepheis.com>. The license is also available online at
// <http://cepheis.com/license.htm>.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE.  See the license for more details.
//
// Version 2.101
//#include "stdafx.h"
#include "DefaultDensityStructure.h"
using namespace Cephei::QL::Termstructures::Credit;
#include <gen/QL/Times/Calendar.h>
#include <gen/QL/Times/DayCounter.h>
#include <gen/QL/Quote.h>
#include <gen/QL/Termstructures/DefaultProbabilityTermStructure.h>
using namespace Cephei::QL::Times;
using namespace Cephei::QL;
using namespace Cephei::QL::Termstructures;
#define HANDLE
#define ABSTRACT
#undef STRUCT
Cephei::QL::Termstructures::Credit::CDefaultDensityStructure::CDefaultDensityStructure (boost::shared_ptr<QuantLib::DefaultDensityStructure>& childNative, Object^ owner) : CDefaultProbabilityTermStructure(CDefaultDensityStructure::typeid)
{
#ifdef HANDLE
	_phDefaultDensityStructure = NULL;
#endif
	_ppDefaultDensityStructure = &childNative;
    _ppDefaultProbabilityTermStructure = new boost::shared_ptr<QuantLib::DefaultProbabilityTermStructure> (boost::dynamic_pointer_cast<QuantLib::DefaultProbabilityTermStructure> (*_ppDefaultDensityStructure));
}
Cephei::QL::Termstructures::Credit::CDefaultDensityStructure::CDefaultDensityStructure (QuantLib::DefaultDensityStructure& childNative, Object^ owner) : CDefaultProbabilityTermStructure(CDefaultDensityStructure::typeid)
{
#ifdef HANDLE
	_phDefaultDensityStructure = NULL;
#endif
	_ppDefaultDensityStructure = new boost::shared_ptr<QuantLib::DefaultDensityStructure> (&childNative);
    _ppDefaultProbabilityTermStructure = new boost::shared_ptr<QuantLib::DefaultProbabilityTermStructure> (boost::dynamic_pointer_cast<QuantLib::DefaultProbabilityTermStructure> (*_ppDefaultDensityStructure));
    _DefaultDensityStructureOwner = owner;
    _DefaultProbabilityTermStructureOwner = owner;
}

Cephei::QL::Termstructures::Credit::CDefaultDensityStructure::CDefaultDensityStructure (CDefaultDensityStructure^ copy) : CDefaultProbabilityTermStructure(CDefaultDensityStructure::typeid)
{
#ifdef HANDLE
	_phDefaultDensityStructure = NULL;
#endif
	if (copy->HasNative() != NULL)
    {
		_ppDefaultDensityStructure = new boost::shared_ptr<QuantLib::DefaultDensityStructure> (copy->GetShared());
        _ppDefaultProbabilityTermStructure = new boost::shared_ptr<QuantLib::DefaultProbabilityTermStructure> (boost::dynamic_pointer_cast<QuantLib::DefaultProbabilityTermStructure> (*_ppDefaultDensityStructure));
    }
}
Cephei::QL::Termstructures::Credit::CDefaultDensityStructure::CDefaultDensityStructure (System::Type^ t) : CDefaultProbabilityTermStructure(CDefaultDensityStructure::typeid)
{
#ifdef HANDLE
	_phDefaultDensityStructure = NULL;
#endif
	if (!t->IsSubclassOf(CDefaultDensityStructure::typeid))
		throw gcnew Exception ("Invalid base-case init");
}
#ifdef HANDLE
Cephei::QL::Termstructures::Credit::CDefaultDensityStructure::CDefaultDensityStructure (QuantLib::Handle<QuantLib::DefaultDensityStructure>& childNative, Object^ owner)  : CDefaultProbabilityTermStructure(CDefaultDensityStructure::typeid)
{
	_phDefaultDensityStructure = &childNative;
	_ppDefaultDensityStructure = &static_cast<boost::shared_ptr<QuantLib::DefaultDensityStructure>>(childNative.currentLink());
    _ppDefaultProbabilityTermStructure = new boost::shared_ptr<QuantLib::DefaultProbabilityTermStructure> (boost::dynamic_pointer_cast<QuantLib::DefaultProbabilityTermStructure> (*_ppDefaultDensityStructure));
    _DefaultDensityStructureOwner = owner;
}
Cephei::QL::Termstructures::Credit::CDefaultDensityStructure::CDefaultDensityStructure (QuantLib::Handle<QuantLib::DefaultDensityStructure> childNative)  : CDefaultProbabilityTermStructure(CDefaultDensityStructure::typeid)
{
	_phDefaultDensityStructure = &childNative;
	_ppDefaultDensityStructure = &static_cast<boost::shared_ptr<QuantLib::DefaultDensityStructure>>(childNative.currentLink());
    _ppDefaultProbabilityTermStructure = new boost::shared_ptr<QuantLib::DefaultProbabilityTermStructure> (boost::dynamic_pointer_cast<QuantLib::DefaultProbabilityTermStructure> (*_ppDefaultDensityStructure));
}
#endif
#ifdef STRUCT
Cephei::QL::Termstructures::Credit::CDefaultDensityStructure::CDefaultDensityStructure (QuantLib::DefaultDensityStructure childNative)  : CDefaultProbabilityTermStructure(CDefaultDensityStructure::typeid)
{
#ifdef HANDLE
	_phDefaultDensityStructure = NULL;
#endif
	_ppDefaultDensityStructure = new boost::shared_ptr<QuantLib::DefaultDensityStructure> (new QuantLib::DefaultDensityStructure (childNative));
    _ppDefaultProbabilityTermStructure = new boost::shared_ptr<QuantLib::DefaultProbabilityTermStructure> (boost::dynamic_pointer_cast<QuantLib::DefaultProbabilityTermStructure> (*_ppDefaultDensityStructure));
}
#endif

Cephei::QL::Termstructures::Credit::CDefaultDensityStructure::~CDefaultDensityStructure ()
{
    if (_ppDefaultDensityStructure != NULL)
    {
	    delete _ppDefaultDensityStructure;
        _ppDefaultDensityStructure = NULL;
    }
}
Cephei::QL::Termstructures::Credit::CDefaultDensityStructure::!CDefaultDensityStructure ()
{
    if (_ppDefaultDensityStructure != NULL)
    {
	    delete _ppDefaultDensityStructure;
    }
}
QuantLib::DefaultDensityStructure& Cephei::QL::Termstructures::Credit::CDefaultDensityStructure::GetReference ()
{
    if (_ppDefaultDensityStructure == NULL) throw gcnew NativeNullException ();
	return **_ppDefaultDensityStructure;
}
boost::shared_ptr<QuantLib::DefaultDensityStructure>& Cephei::QL::Termstructures::Credit::CDefaultDensityStructure::GetShared ()
{
    if (_ppDefaultDensityStructure == NULL) throw gcnew NativeNullException ();
	return *_ppDefaultDensityStructure;
}
QuantLib::DefaultDensityStructure* Cephei::QL::Termstructures::Credit::CDefaultDensityStructure::GetPointer ()
{
    if (_ppDefaultDensityStructure == NULL) throw gcnew NativeNullException ();
	return &**_ppDefaultDensityStructure;
}
#ifdef HANDLE
QuantLib::Handle<QuantLib::DefaultDensityStructure>& Cephei::QL::Termstructures::Credit::CDefaultDensityStructure::GetHandle ()
{
	if (_phDefaultDensityStructure == NULL)
	{
		_phDefaultDensityStructure = new Handle<QuantLib::DefaultDensityStructure> (*_ppDefaultDensityStructure);
	}
	return *_phDefaultDensityStructure;
}
#endif
bool Cephei::QL::Termstructures::Credit::CDefaultDensityStructure::HasNative () 
{
	return (_ppDefaultDensityStructure != NULL);
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Factory class

